package aop2;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author <a href="mailto:ifonlymaster@163.com">ifonly</a>
 * @version 1.0 2015-12-10 09:08
 * @since JDK 1.6
 */
public class DynaProxyHello implements InvocationHandler {
    private Object target;

    //动态生成代理对象
    public Object bind(Object target) {
        this.target = target;
        return Proxy.newProxyInstance(this.target.getClass().getClassLoader(),
                this.target.getClass().getInterfaces(),
                this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before..... ");
        Object result=method.invoke(target,args);
        System.out.println("after.....");
        return result;
    }
}
